********************************************************************************
*   Do-File for Replication of Appendix Tables A.1-A.29
*	"Bring a Friend: Leveraging Financial and Peer Support to Improve Women's Reproductive Agency in India"
*	By: S Anukriti, Catalina Herrera-Almanza, Mahesh Karra
*	Date: 17 December 2025
********************************************************************************

************************************************
**# B. Data Import and Index Construction
*************************************************

clear all


* Data import
use "$repo/data_endline_final.dta", clear



**##  Construction of z-score indices for main outcomes (Tables 2-5)    

cap drop z_table*

drop if missing(base_school_yrs, base_current_fp, ///
				base_wants_child, base_num_friend, ///
				base_mobi, base_work, base_ever_visit_fp, ///
				base_mod_method, base_phone)
				
				
// Reverse-coding for FP attitudes and pregnancy outcomes to align with treatment effects
cap drop afraid_being_seen_neg
gen afraid_being_seen_neg = 1 - afraid_being_seen
cap drop preg_ever_neg
gen preg_ever_neg = 1 - preg_ever


global outcomes2 ask_peer_adc asked_hmil asked_other asked_sil asked_nonfam
global outcomes3 visit_adc_fp_corr visit_any_fp_new_corr visit_adc_alone /// 
				 visit_adc_w_hhmil_new visit_adc_w_nohmil_new visit_adc_w_sil_new ///
				 visit_adc_w_other_new				 
			 
global outcomes4 heard_mod_method /// 
				 afraid_being_seen_neg  /// 
				 mod_method_el mod_method_since_bl /// 
				 wants_child preg_ever_neg
global outcomes5 outsider_new  /// 
				 atleast1_visithf_VoutHH2 peer_advise_FP_VoHH2
			 
foreach n in 2 3 4 5 {
    
    // Build macro names
    local in_macro outcomes`n'
    local tmp_macro outcomes`n'_tmp
    local zvar z_table`n'

    // Initialize the global for _tmp vars
    global `tmp_macro'

    // Create missflag based on all variables in the group
    cap drop missflag
    egen missflag = rowmiss($`in_macro')

    // Loop over each variable and create _tmp version with conditional missing
    foreach y of global `in_macro' {
        cap drop `y'_tmp
        gen `y'_tmp = `y'
        replace `y'_tmp = . if missflag > 0
        global `tmp_macro' $`tmp_macro' `y'_tmp
    }

    // Create weighted average summary
    cap drop `zvar'
    egen `zvar' = weightave2($`tmp_macro')

    // Clean up
  
}

// Defining common covariates across regressions
global covbal base_school_yrs base_current_fp base_wants_child base_num_friend
global cov  base_mobi base_work base_ever_visit_fp base_mod_method base_phone


************************************
**# C. Tables in Online Appendix
************************************


***********************************************************************************
**## Table A.1: Balance at baseline for the estimation sample: Additional variables 
***********************************************************************************
eststo clear
est drop _all
 
global balance base_age base_school_yrs base_w_hindu base_scst base_obc 	///
			   base_ghunghat base_work base_livewMIL base_mobi 				///
			   base_asset_score base_num_friend base_outsider 			    ///
			   base_no_children base_wants_child base_current_fp 			///
			   base_mod_method base_ever_visit_fp base_costFP_MILopposed
 
global othervars base_poor base_durationmarriage base_at_least_1_son 		 ///
				 base_concealabilityFP base_costFP_embarrasing ///
				 base_nopeeruseFPvill base_went_hmil 

* Mean . SD of each treatment arm:
eststo control:  estpost summarize $othervars if treatment == 0
eststo own:  	 estpost summarize $othervars if treatment == 1 
eststo baf:  	 estpost summarize $othervars if treatment == 2 

* Pair-differences
eststo diffcontrolown:  estpost ttest $othervars if treatment!=2, by(solo) unequal 

*Adding scalars of F-Test of join significance. 
reg solo $othervars $balance   if treatment!=2
estadd scalar F_Obs = `e(N)': diffcontrolown
testparm $othervars $balance
estadd scalar F_pvalue = r(p): diffcontrolown


eststo diffcontrolbaf:   estpost ttest $othervars if treatment!=1, by(baf) unequal 


*Adding scalars of F-Test of join significance. 
reg baf $othervars $balance   if treatment!=1
estadd scalar F_Obs = `e(N)': diffcontrolbaf
testparm $othervars $balance
estadd scalar F_pvalue = r(p): diffcontrolbaf


eststo diffownbaf:   estpost ttest $othervars if treatment!=0, by(baf) unequal 


* Adding scalars of F-Test of join significance. 
reg baf $othervars $balance   if treatment!=0
estadd scalar F_Obs = `e(N)': diffownbaf
testparm $othervars $balance
estadd scalar F_pvalue = r(p): diffownbaf

la var base_went_hmil "Last visit to a FP clinic was with husband or MIL"

* Export Balance Table: 

esttab ///
control own baf  diffcontrolown diffcontrolbaf diffownbaf ///
using "$repo/tables/appendix_table1.tex"  , ///
cells("count(pattern(1 1 1 0 0 0 ) fmt(0)) mean(pattern(1 1 1 0 0 0) fmt(3)) b(star pattern(0 0 0 1 1 1) fmt(3))" ". sd(pattern(1 1 1 0 0 0) par fmt(3))" ) ///
label  varlabels(base_nopeeruseFPvill "Lack of close peers in village that use FP$^\text{a}$" ) collabels(none) nonum plain nomtitle noobs not tex starlevels(* 0.1 ** .05  *** .01) ///
stats(F_pvalue F_Obs, label("\midrule F-test of joint significance: p-value" "F-test: Number of observations" ) fmt( %9.3f  %9.0f )) ///
prehead("\begin{tabular}{lccccccccc} \toprule & \multicolumn{2}{c}{Control (C)}   & \multicolumn{2}{c}{Own}  &  \multicolumn{2}{c}{BAF}  & C - Own & C - BAF & Own - BAF \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(lr){8-8} \cmidrule(lr){9-9} \cmidrule(lr){10-10}  & N & Mean/SD & N & Mean/SD & N & Mean/SD & Diff. & Diff. & Diff. \\ & (1) & (2) &(3)& (4) & (5) & (6) & (7) & (8) & (9) \\ \midrule") ///
posthead("") ///
postfoot("\bottomrule  \\[-5ex] \end{tabular}") replace


**********************************************************************
**## Table A.2: Summary of the number of observations for each outcome 
**********************************************************************

* Please refer to the R script file.

****************************************************************
**## Table A.3: Descriptive statistics for the estimation sample
****************************************************************

eststo clear
est drop _all

 
 * Globals:
global varstats_outcomes  ask_peer_adc asked_hmil  ///
						  asked_other asked_sil asked_nonfam num_peers_asked_adc outsider_new ///
						  afraid_being_seen  ///
						  visit_adc_fp_corr visit_any_fp_new_corr ///
						  visit_adc_alone visit_adc_w_hhmil_new visit_adc_w_nohmil_new ///
						  visit_adc_w_sil_new ///
						  mod_method_el mod_method_since_bl preg_ever
global varstats_balancing  base_school_yrs base_current_fp ///
						   base_wants_child base_num_friend 
global varstats_othersvars  base_age base_w_hindu base_scst base_obc ///
							base_ghunghat base_work base_mobi ///
							base_ever_visit_fp base_asset_score
global vars_heteffect   base_costFP_MILopposed  base_concealabilityFP ///
						base_costFP_embarrasing  base_nopeeruseFPvill base_poor 

* Adding footnote symbols to variables that need it: 

*Phone survey footnote
la var asked_hmil "Sought company from husband or MIL to visit the ADC"
la var asked_other "Sought company from other than husband or MIL to visit the ADC"
la var asked_sil "Sought company from sister or SIL to visit the ADC"
la var asked_nonfam "Sought company from a non-relative to visit the ADC"
la var outsider_new "Number of close peers outside HH in village"
la var afraid_being_seen "Afraid of being seen at a health facility"
la var visit_adc_w_hhmil "Visited the ADC with Husband or MIL"
la var visit_adc_w_nohmil "Visited the ADC with other than husband or MIL"
* Other explanation footnote:
la var base_nopeeruseFPvill "No baseline close peers in village using FP"
* Another explanation footnote
la var mod_method_el "Currently using modern FP method"
la var mod_method_since_bl "Using modern FP method since baseline"
la var preg_ever "Ever pregnancy"
la var curr_fp_endline "Currently using FP method"

* Export table:
estpost summ $varstats_outcomes 
esttab using "$repo/tables/appendix_table3.tex" , ///
cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0))") ///
nomtitle noobs nonumber label collabels(none)  varwidth(25) ///
varlabels(ask_peer_adc "\emph{Sought company to visit the ADC from:} & & & & & \\ \quad Someone" ///
asked_hmil "\quad Husband or MIL" ///
asked_other "\quad Someone other than husband or MIL" ///
asked_sil "\quad Sister-in-law" ///
asked_nonfam "\quad Non-relative" ///
outsider_new  "Number of close peers outisde HH in village" ///
num_friend_2village "Number of close peers in village" ///
afraid_being_seen "Afraid of being seen at a health facility" ///
visit_adc_alone "\emph{Visited the ADC:} & & & & & \\ \quad Alone" ///
visit_adc_w_hhmil_new "\quad With husband or MIL" ///
visit_adc_w_nohmil_new "\quad With someone other than husband or MIL" ///
visit_adc_w_sil_new "\quad With Sister-in-law") ///
prehead("\begin{tabular}{lccccc}\toprule & N & Mean & SD & Min & Max \\ & (1) & (2) & (3) & (4) & (5) \\  ") ///
posthead("\midrule \multicolumn{6}{l}{\textit{Endline variables}}\\ \midrule") ///
postfoot("") nogaps replace

estpost summ $varstats_balancing $varstats_othersvars $vars_heteffect 
esttab using "$repo/tables/appendix_table3.tex" , ///
cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0))") ///
nomtitle noobs nonumber label    mlabels(none) collabels(none) varwidth(25) ///
prehead("\midrule") ///
posthead(" \multicolumn{6}{l}{\textit{Baseline variables}}\\  \midrule") nogaps ///
postfoot("\bottomrule  \\[-5ex] \end{tabular}") append


*********************************************************************************
**## Table A.4: External Validity: Comparing our endline sample with 2019-21 NFHS
*********************************************************************************

* Externally calculated by the authors. Please refer to appendix_table4.tex.

************************************************
**## Table A.5 : Sought company to visit the ADC
************************************************

eststo clear
est drop _all

global outcome 	ask_peer_adc num_peers_asked_adc  asked_hmil asked_other 		///
				asked_sil asked_nonfam visit_adc_fp_corr visit_any_fp_new_corr 	///
				num_visit_adc_corr num_fp_visit_new

foreach y of global outcome{
eststo reg`y'1: reg `y' solo baf , robust
	test _b[solo]=_b[baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0 
	estadd scalar controlmean = r(mean)	
	
	estadd local Balance "No"
	estadd local Covariates "No"
	estadd local FE  "No"
	
eststo reg`y'2: reg `y' solo baf  $covbal  , robust 
	test _b[solo]=_b[baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0 
	estadd scalar controlmean = r(mean)	

	estadd local Balance "Yes"
	estadd local Covariates "No"
	estadd local FE  "No"

	
eststo reg`y'3: reg `y' solo baf  $covbal $cov , robust 
	test _b[solo]=_b[baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0 
	estadd scalar controlmean = r(mean)	

	estadd local Balance "Yes"
	estadd local Covariates "Yes"
	estadd local FE  "No"

	
eststo reg`y'4: reg `y' solo baf  $covbal $cov  i.base_village_num , robust 
	test _b[solo]=_b[baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0 
	estadd scalar controlmean = r(mean)	

	estadd local Balance "Yes"
	estadd local Covariates "Yes"
	estadd local FE  "Yes"
	
}

esttab regask_peer_adc* ///
using "$repo/tables/appendix_table5.tex" , ///
keep(solo baf) ///
label mlabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noline collabels(none) noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N controlmean pvalue , label("\midrule Observations" "Endline control mean" "p-value: Own = BAF"  ) fmt(%9.0f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccc}\toprule") ///
posthead(" & (1) & (2) & (3) & (4)  \\ \midrule  \multicolumn{5}{l}{\textbf{A: Sought company from someone}} \\ \midrule") nogaps ///
postfoot("\midrule") ///
sfmt(%9.2f) varwidth(25)  replace

esttab regasked_hmil* ///
using "$repo/tables/appendix_table5.tex" , ///
keep(solo baf) ///
label mlabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noline collabels(none) noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  controlmean pvalue , label("\midrule Observations"  "Endline control mean"  "p-value: Own = BAF") fmt(%9.0f %9.3f %9.3f)) ///
prehead("") ///
posthead("\multicolumn{5}{l}{\textbf{B: Sought company from husband or mother-in-law}} \\ \midrule") nogaps ///
postfoot("\midrule") ///
sfmt(%9.2f) varwidth(30)  append

esttab regasked_other* ///
using "$repo/tables/appendix_table5.tex" , ///
keep(solo baf) ///
label mlabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noline collabels(none) noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  pvalue controlmean Balance Covariates FE, label("\midrule Observations" "p-value: Own = BAF" "Endline control mean" "\midrule Balancing controls" "Other balancing covariates" "Village FE") fmt(%9.0f %9.3f %9.3f)) ///
prehead("") ///
posthead(" \multicolumn{5}{l}{\textbf{C: Sought company from someone other than husband or mother-in-law}} \\ \midrule") nogaps ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  append
 

************************************************************************
**## Table A.6 : Number and composition of peers sought to visit the ADC
************************************************************************

esttab regnum_peers_asked_adc* ///
using "$repo/tables/appendix_table6.tex" , ///
keep(solo baf) ///
label mlabels(none) noline collabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  controlmean pvalue , label("\midrule Observations" "Endline control mean" "p-value: Own=BAF"  ) fmt(%9.0f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccc}\toprule") ///
posthead(" & (1) & (2) & (3) & (4)  \\ \midrule  \multicolumn{5}{l}{\textbf{A: Number of peers sought}} \\ \midrule") nogaps ///
postfoot("\midrule") ///
sfmt(%9.2f) varwidth(25)  replace

esttab regasked_sil* ///
using "$repo/tables/appendix_table6.tex" , ///
keep(solo baf) ///
label mlabels(none) noline collabels(none)  se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  controlmean pvalue , label("\midrule Observations" "Endline control mean"  "p-value: Own=BAF" ) fmt(%9.0f %9.3f %9.3f)) ///
prehead("") ///
posthead("\multicolumn{5}{l}{\textbf{B: Sought company from sister-in-law}} \\ \midrule") nogaps ///
postfoot("\midrule") ///
sfmt(%9.2f) varwidth(30)  append

esttab regasked_nonfam* ///
using "$repo/tables/appendix_table6.tex" , ///
keep(solo baf) ///
label mlabels(none) noline collabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N controlmean  pvalue  Balance Covariates FE, label("\midrule Observations" "Endline control mean"  "p-value: Own=BAF" "\midrule Balancing controls" "Other balancing covariates" "Village FE") fmt(%9.0f %9.3f %9.3f)) ///
prehead("") ///
posthead(" \multicolumn{5}{l}{\textbf{C: Sought company from a non-relative}} \\ \midrule") nogaps ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  append


******************************************************************************************************
**## Table A.7: Summary of the number of observations for each outcome used in the Tables 2-5 indices
******************************************************************************************************

* Please refer to the R script file to construct final formatted appendix_table7.tex file.

*************************************************************
**## Table A.8 : Clinic visits for family planning services
*************************************************************

esttab regvisit_adc_fp_corr* ///
using "$repo/tables/appendix_table8.tex" , ///
keep(solo baf) ///
label mlabels(none) noline collabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  controlmean pvalue , label("\midrule Observations" "Endline control mean" "p-value: Own = BAF"  ) fmt(%9.0f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccc}\toprule") ///
posthead(" & (1) & (2) & (3) & (4)  \\ \midrule  \multicolumn{5}{l}{\textbf{A: Visited the ADC}} \\ \midrule") nogaps ///
postfoot("\midrule") ///
sfmt(%9.2f) varwidth(25)  replace

esttab regvisit_any_fp_new_corr* ///
using "$repo/tables/appendix_table8.tex" , ///
keep(solo baf) ///
label mlabels(none) noline collabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  controlmean pvalue  Balance Covariates FE, label("\midrule Observations" "Endline control mean"  "p-value: Own = BAF" "\midrule Balancing controls" "Other balancing covariates" "Village FE") fmt(%9.0f %9.3f %9.3f)) ///
prehead("") ///
posthead(" \multicolumn{5}{l}{\textbf{B: Visited any clinic}} \\ \midrule") nogaps ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  append


******************************************************************************************************
**## Table A.10:  Number of clinic visits for family planning services during the intervention period
******************************************************************************************************
 
esttab regnum_visit_adc_corr* ///
using "$repo/tables/appendix_table10.tex" , ///
keep(solo baf) ///
label mlabels(none) noline collabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  controlmean pvalue , label("\midrule Observations" "Endline control mean"  "p-value: Own=BAF" ) fmt(%9.0f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccc}\toprule") ///
posthead(" & (1) & (2) & (3) & (4)  \\ \midrule  \multicolumn{5}{l}{\textbf{A: Number of visits to the ADC}} \\ \midrule") nogaps ///
postfoot("\midrule") ///
sfmt(%9.2f) varwidth(25)  replace

esttab regnum_fp_visit_new* ///
using "$repo/tables/appendix_table10.tex" , ///
keep(solo baf) ///
label mlabels(none) noline collabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  controlmean pvalue  Balance Covariates FE, label("\midrule Observations" "Endline control mean" "p-value: Own = BAF"  "\midrule Balancing controls" "Other balancing covariates" "Village FE") fmt(%9.0f %9.3f %9.3f)) ///
prehead("") ///
posthead(" \multicolumn{5}{l}{\textbf{B: Number of visits to any clinic}} \\ \midrule") nogaps ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  append


********************************************************************************************
**## Table A.9: Clinic visits for family planning services, using administrative record data
********************************************************************************************

preserve

merge 1:1 caseid using "$repo/clinic_visit.dta"
drop if _merge == 2

replace visit_adc_admin = 0 if visit_adc_admin == .


eststo clear
est drop _all

global visits  	visit_adc_fp_corr visit_adc_admin

foreach y of global visits{
eststo r`y'0: reg `y' solo baf $covbal $cov i.base_village_num  , r

test _b[solo]=_b[baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0 
	estadd scalar controlmean = r(mean)		
}


esttab  rvisit_adc_fp_corr0 rvisit_adc_admin0 ///
using "$repo/tables/appendix_table9.tex" , ///
keep(solo baf) ///
label mlabels(none) collabels(none)  se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nolines  nogaps starlevels( * 0.1 ** .05  *** .01) ///
stats(N  controlmean pvalue , label("\midrule Observations" "Endline control mean" "p-value: Own = BAF" ) fmt(%9.0f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcc} \toprule") ///
posthead("& \textbf{\shortstack{Visited the\\ ADC}} & \textbf{\shortstack{Visited the\\ ADC (Admin)}}\\  & (1) & (2) \\ \midrule") ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  replace

restore


************************************************************************************
**## Table A.11: Heterogeneous effects on clinic visits for family planning services
************************************************************************************

eststo clear
est drop _all

global outcome visit_any_fp_new_corr 
    
 foreach y of global outcome{
 
eststo reg`y'1: reg `y' i.solo##i.base_wants_child  i.baf##i.base_wants_child   ///
						c.base_school_yrs#i.base_wants_child    ///
						c.base_num_friend#i.base_wants_child    ///
						i.base_current_fp##i.base_wants_child  ///
						i.base_wants_child##i.base_wants_child  ///
						i.base_obc##i.base_wants_child  ///
						c.base_mobi#i.base_wants_child  ///
						i.base_work##i.base_wants_child  ///
						i.base_wants_child##i.base_wants_child   ///
						i.base_phone#i.base_wants_child  ///
						i.base_mod_method#i.base_wants_child ///
						i.base_village_num#i.base_wants_child ,  r
						

test _b[1.solo] = _b[1.baf]
estadd scalar pvalue1 = r(p)

test _b[1.solo#1.base_wants_child ] = _b[1.baf#1.base_wants_child ]
estadd scalar pvalue2 = r(p)

test _b[1.solo] + _b[1.solo#1.base_wants_child ] = 0
estadd scalar pvalue3 = r(p)

test _b[1.baf] + _b[1.baf#1.base_wants_child ] = 0
estadd scalar pvalue4 = r(p)

sum `y' if treatment == 0 
estadd scalar controlmean = r(mean)	
 	
	
eststo reg`y'2: reg `y' i.solo##i.base_at_least_1_son  i.baf##i.base_at_least_1_son   ///
						c.base_school_yrs#i.base_at_least_1_son    ///
						c.base_num_friend#i.base_at_least_1_son    ///
						i.base_current_fp##i.base_at_least_1_son  ///
						i.base_wants_child##i.base_at_least_1_son  ///
						i.base_obc##i.base_at_least_1_son  ///
						c.base_mobi#i.base_at_least_1_son  ///
						i.base_work##i.base_at_least_1_son  ///
						i.base_at_least_1_son##i.base_at_least_1_son   ///
						i.base_phone#i.base_at_least_1_son  ///
						i.base_mod_method#i.base_at_least_1_son ///
						i.base_village_num#i.base_at_least_1_son ,  r
						
test _b[1.solo] = _b[1.baf]
estadd scalar pvalue1 = r(p)

test _b[1.solo#1.base_at_least_1_son ] = _b[1.baf#1.base_at_least_1_son ]
estadd scalar pvalue2 = r(p)

test _b[1.solo] + _b[1.solo#1.base_at_least_1_son ] = 0
estadd scalar pvalue3 = r(p)

test _b[1.baf] + _b[1.baf#1.base_at_least_1_son ] = 0
estadd scalar pvalue4 = r(p)

sum `y' if treatment == 0 
estadd scalar controlmean = r(mean)	


*****	
	
eststo reg`y'3: reg `y' i.solo##i.base_ever_visit_fp i.baf##i.base_ever_visit_fp   ///
						c.base_school_yrs#i.base_ever_visit_fp    ///
						c.base_num_friend#i.base_ever_visit_fp    ///
						i.base_current_fp##i.base_ever_visit_fp  ///
						i.base_wants_child##i.base_ever_visit_fp  ///
						i.base_obc##i.base_ever_visit_fp  ///
						c.base_mobi#i.base_ever_visit_fp  ///
						i.base_work##i.base_ever_visit_fp  ///
						i.base_ever_visit_fp##i.base_ever_visit_fp   ///
						i.base_phone#i.base_ever_visit_fp  ///
						i.base_mod_method#i.base_ever_visit_fp ///
						i.base_village_num#i.base_ever_visit_fp ,  r
						
* reg 3 doesn't control for base_ever_visitFP, since we are using it to interact the model.
						
test _b[1.solo] = _b[1.baf]
estadd scalar pvalue1 = r(p)

test _b[1.solo#1.base_ever_visit_fp ] = _b[1.baf#1.base_ever_visit_fp ]
estadd scalar pvalue2 = r(p)

test _b[1.solo] + _b[1.solo#1.base_ever_visit_fp ] = 0
estadd scalar pvalue3 = r(p)

test _b[1.baf] + _b[1.baf#1.base_ever_visit_fp ] = 0
estadd scalar pvalue4 = r(p)

sum `y' if treatment == 0 
estadd scalar controlmean = r(mean)	
}
 
  
esttab regvisit_any_fp_new_corr1 regvisit_any_fp_new_corr2 regvisit_any_fp_new_corr3 ///
using "$repo/tables/appendix_table11.tex" , ///
rename(1.base_at_least_1_son 1.base_wants_child 1.base_ever_visit_fp 1.base_wants_child ///
1.solo#1.base_at_least_1_son 1.solo#1.base_wants_child ///
1.solo#1.base_ever_visit_fp 1.solo#1.base_wants_child ///
1.baf#1.base_at_least_1_son 1.baf#1.base_wants_child ///
1.baf#1.base_ever_visit_fp 1.baf#1.base_wants_child ) ///
keep(1.solo  1.solo#1.base_wants_child  1.baf 1.baf#1.base_wants_child   ) ///
order(1.solo  1.baf  1.solo#1.base_wants_child 1.baf#1.base_wants_child ) ///
varlabels(1.solo "Own Voucher" 1.baf "BAF Voucher" 1.solo#1.base_wants_child "Own Voucher $\times$ Covariate" 1.baf#1.base_wants_child "BAF Voucher $\times$ Covariate" ) ///
mlabels(none)  collabels(none) nolines se(%9.3f) b(%9.3f)  brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01)  ///
stats(N  controlmean pvalue1 pvalue2 pvalue3 pvalue4 , label("\midrule Observations" "Endline control mean"  "\shortstack[l]{p-values:\\Own = BAF}"   "Own $\times$ Covariate = BAF $\times$ Covariate" "Own + Own $\times$ Covariate = 0"  "BAF + BAF $\times$ Covariate = 0" ) fmt(%9.0f %9.3f %9.3f  %9.3f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lccc} \toprule") ///
posthead(" &  \multicolumn{3}{c}{Covariate at baseline:}  \\ \cmidrule(lr){2-4} \textbf{Outcome:}  &  \shortstack{Wanted another\\child} & \shortstack{Had at least\\one son} & \shortstack{Had ever visited\\a clinic for FP}  \\  \textbf{Visited any clinic} & (1) & (2) & (3) \\ \midrule") ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  replace


***********************************************************************
**## Table A.12: Family planning and fertility outcomes since baseline
***********************************************************************
eststo clear
est drop _all

global outcomes curr_since_bl mod_method_since_bl preg_ever

foreach y of global outcomes{

eststo reg`y'1: reg `y' i.solo i.baf , r
	test _b[1.solo]=_b[1.baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0
	estadd scalar controlmean = r(mean)	
	estadd local Balance  "No"
	estadd local Covariates "No"
	estadd local FE  "No"
eststo reg`y'2: reg `y' i.solo i.baf $covbal  , r
	test _b[1.solo]=_b[1.baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0
	estadd scalar controlmean = r(mean)	
	estadd local Balance  "Yes"
	estadd local Covariates "No"
	estadd local FE  "No"
eststo reg`y'3: reg `y' i.solo i.baf $covbal $cov , r
	test _b[1.solo]=_b[1.baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0 
	estadd scalar controlmean = r(mean)	
	estadd local Balance "Yes"
	estadd local Covariates "Yes"
	estadd local FE  "No"
eststo reg`y'4: reg `y' i.solo i.baf $covbal $cov i.base_village_num , r
	test _b[1.solo]=_b[1.baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0 
	estadd scalar controlmean = r(mean)	
	estadd local Balance "Yes"
	estadd local Covariates "Yes"
	estadd local FE  "Yes"
	
}

esttab  regcurr_since_bl*  ///
using "$repo/tables/appendix_table12.tex" , ///
keep(1.solo 1.baf) ///
label mlabels(none)  collabels(none) noline se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  pvalue controlmean, label("\midrule Observations" "p-value: Own=BAF" "Endline control mean" ) fmt(%9.0f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccc} \toprule") ///
posthead(" & (1) & (2) & (3) & (4)  \\ \midrule   \multicolumn{5}{l}{\textbf{A: Using FP since baseline}} \\ \midrule") ///
postfoot("\midrule") ///
sfmt(%9.2f) varwidth(25)  replace


esttab  regmod_method_since_bl* ///
using "$repo/tables/appendix_table12.tex" , ///
keep(1.solo 1.baf) ///
label mlabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N  pvalue controlmean, label("Observations" "p-value: Own = BAF" "Endline control mean") fmt(%9.0f %9.3f %9.3f)) ///
prehead("") ///
posthead("   \multicolumn{5}{l}{\textbf{B: Using modern FP since baseline}} \\ \midrule ") ///
postfoot("\midrule") ///
 sfmt(%9.2f) varwidth(25) append

 
esttab  regpreg_ever* ///
using "$repo/tables/appendix_table12.tex" , ///
keep(1.solo 1.baf) ///
label mlabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ////
stats(N pvalue controlmean Balance Covariates FE, label("Observations" "p-value: Own = BAF" "Endline control mean"  "\midrule Balancing controls" "Other balancing covariates" "Village FE") fmt(%9.0f %9.3f %9.3f)) ///
prehead("") ///
posthead("   \multicolumn{5}{l}{\textbf{C: Ever pregnant}} \\ \midrule ") ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  append


*******************************************************************************************************************
**## Table A.13: Heterogeneous effects on social connections and peer engagement by social connections at baseline
********************************************************************************************************************


eststo clear
est drop _all	

global outcomes outsider_new  ///
				atleast1_visithf_VoutHH2 peer_advise_FP_VoHH2 ///
				z_table5


foreach y of global outcomes{
	
eststo r`y'0: reg `y' i.solo##i.base_nopeeruseFPvill   i.baf##i.base_nopeeruseFPvill   ///
						c.base_school_yrs#i.base_nopeeruseFPvill    ///
						c.base_num_friend#i.base_nopeeruseFPvill    ///
						i.base_current_fp##i.base_nopeeruseFPvill  ///
						i.base_wants_child##i.base_nopeeruseFPvill  ///
						i.base_obc##i.base_nopeeruseFPvill  ///
						c.base_mobi#i.base_nopeeruseFPvill  ///
						i.base_work##i.base_nopeeruseFPvill  ///
						i.base_ever_visit_fp##i.base_nopeeruseFPvill   ///
						i.base_phone#i.base_nopeeruseFPvill  ///
						i.base_mod_method#i.base_nopeeruseFPvill ///
						i.base_village_num#i.base_nopeeruseFPvill ,  r
						
test _b[1.solo] = _b[1.baf]
estadd scalar pvalue1 = r(p)

test _b[1.solo#1.base_nopeeruseFPvill] = _b[1.baf#1.base_nopeeruseFPvill]
estadd scalar pvalue2 = r(p)

test _b[1.solo] + _b[1.solo#1.base_nopeeruseFPvill ] = 0
estadd scalar pvalue3 = r(p)

test _b[1.baf] + _b[1.baf#1.base_nopeeruseFPvill ] = 0
estadd scalar pvalue4 = r(p)

sum `y' if treatment == 0 
estadd scalar controlmean = r(mean)	

}

esttab routsider_new0 ratleast1_visithf_VoutHH20 rpeer_advise_FP_VoHH20 rz_table50 ///
using "$repo/tables/appendix_table13.tex" , ///
keep(1.solo  1.solo#1.base_nopeeruseFPvill  1.baf 1.baf#1.base_nopeeruseFPvill  ) ///
order(1.solo  1.baf  1.solo#1.base_nopeeruseFPvill 1.baf#1.base_nopeeruseFPvill  ) ///
varlabels(1.solo "Own Voucher" 1.baf "BAF Voucher" 1.solo#1.base_nopeeruseFPvill "Own Voucher $\times$ Covariate" 1.baf#1.base_nopeeruseFPvill "BAF  Voucher $\times$ Covariate" ) ///
mlabels(none) se(%9.3f) b(%9.3f)  brackets nonum  noobs nolines collabels(none)   nogaps starlevels( * 0.1 ** .05  *** .01)  ///
stats(N  controlmean pvalue1 pvalue2 pvalue3 pvalue4 , label("\midrule Observations" "Endline control mean" "\shortstack[l]{p-values:\\Own = BAF}"   "Own $\times$ Covariate = BAF $\times$ Covariate" "Own + Own $\times$ Covariate = 0"  "BAF + BAF $\times$ Covariate = 0"  ) fmt(%9.0f %9.3f %9.3f  %9.3f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccc}\toprule") ///
 posthead(" &  \multicolumn{4}{c}{Covariate at baseline: Lack of close peers in village that use FP} \\ \cmidrule(lr){2-5}  & &  \multicolumn{2}{c}{Has close peers outside HH in village that: } \\ \cmidrule(lr){3-4} &  \shortstack{Number of close peers\\outside HH in village} &   \shortstack{Accompanied to\\health facility}  &  \shortstack{Advised woman\\to use FP} &  \shortstack{Table 6\\index} \\  & (1) & (2) & (3) & (4)  \\  \midrule") ///
 postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  replace



************************************************************************************************************************************************
**## Table A.14 : Heterogeneous effects on the type of peers sought and visits to ADC by mother-in-law opposition to family planning at baseline
************************************************************************************************************************************************

eststo clear
est drop _all

global outcomes  asked_sil asked_nonfam visit_adc_w_sil visit_adc_w_other

foreach y of global outcomes{
eststo reg`y': reg `y' i.solo##i.base_costFP_MILopposed   i.baf##i.base_costFP_MILopposed   ///
						c.base_school_yrs#i.base_costFP_MILopposed    ///
						c.base_num_friend#i.base_costFP_MILopposed    ///
						i.base_current_fp##i.base_costFP_MILopposed  ///
						i.base_wants_child##i.base_costFP_MILopposed  ///
						i.base_obc##i.base_costFP_MILopposed  ///
						c.base_mobi#i.base_costFP_MILopposed  ///
						i.base_work##i.base_costFP_MILopposed  ///
						i.base_ever_visit_fp##i.base_costFP_MILopposed   ///
						i.base_phone#i.base_costFP_MILopposed  ///
						i.base_mod_method#i.base_costFP_MILopposed ///
						i.base_village_num#i.base_costFP_MILopposed ,  r
						
test _b[1.solo] = _b[1.baf]
estadd scalar pvalue1 = r(p)

test _b[1.solo#1.base_costFP_MILopposed ] = _b[1.baf#1.base_costFP_MILopposed ]
estadd scalar pvalue2 = r(p)

test _b[1.solo] + _b[1.solo#1.base_costFP_MILopposed ] = 0
estadd scalar pvalue3 = r(p)

test _b[1.baf] + _b[1.baf#1.base_costFP_MILopposed ] = 0
estadd scalar pvalue4 = r(p)

sum `y' if treatment == 0 
estadd scalar controlmean = r(mean)	
}

esttab _all ///
using "$repo/tables/appendix_table14.tex" , ///
keep(1.solo  1.solo#1.base_costFP_MILopposed  1.baf 1.baf#1.base_costFP_MILopposed  ) ///
order(1.solo  1.baf  1.solo#1.base_costFP_MILopposed 1.baf#1.base_costFP_MILopposed ) ///
varlabels(1.solo "Own Voucher" 1.baf "BAF Voucher" 1.solo#1.base_costFP_MILopposed "Own Voucher $\times$ MIL opposed to FP" 1.baf#1.base_costFP_MILopposed "BAF Voucher $\times$ MIL opposed to FP" ) ///
mlabels(none) collabels(none) nolines se(%9.3f) b(%9.3f)  brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01)  ///
stats(N  controlmean pvalue1 pvalue2 pvalue3 pvalue4 , label("\midrule Observations" "Endline control mean" "\shortstack[l]{p-values:\\Own = BAF}"   "Own $\times$ MIL opposed = BAF $\times$ MIL opposed" "Own + Own $\times$ MIL opposed = 0"  "BAF + BAF $\times$ MIL opposed = 0"  ) fmt(%9.0f %9.3f %9.3f  %9.3f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccc}\toprule") ///
posthead(" & \multicolumn{2}{c}{\textbf{Sought company to visit the ADC from:}} & \multicolumn{2}{c}{\textbf{Visit ADC with:}} \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5}  &   Sister-in-law & Non-relative &   Sister-in-law & Non-relative  \\  & (1) & (2) & (3) & (4) \\ \midrule") ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  replace



***********************************************************************************************************
**## Table A.15: Heterogeneous effects by mother-in-law opposition at baseline on FP and fertility outcomes
***********************************************************************************************************
eststo clear
est drop _all

global outcomes heard_mod_method /// // Knowledge
				afraid_being_seen  /// // Attitude
				mod_method_el mod_method_since_bl /// Use of FP
				preg_ever wants_child // Fertility

foreach y of global outcomes{
eststo reg`y': reg `y' 	i.solo##i.base_costFP_MILopposed  ///
						i.baf##i.base_costFP_MILopposed   ///
						c.base_school_yrs#i.base_costFP_MILopposed    ///
						c.base_num_friend#i.base_costFP_MILopposed    ///
						i.base_current_fp##i.base_costFP_MILopposed  ///
						i.base_wants_child##i.base_costFP_MILopposed  ///
						i.base_obc##i.base_costFP_MILopposed  ///
						c.base_mobi#i.base_costFP_MILopposed  ///
						i.base_work##i.base_costFP_MILopposed  ///
						i.base_ever_visit_fp##i.base_costFP_MILopposed   ///
						i.base_phone#i.base_costFP_MILopposed  ///
						i.base_mod_method#i.base_costFP_MILopposed ///
						i.base_village_num#i.base_costFP_MILopposed ,  r
						
test _b[1.solo] = _b[1.baf]
estadd scalar pvalue1 = r(p)

test _b[1.solo#1.base_costFP_MILopposed ] = _b[1.baf#1.base_costFP_MILopposed ]
estadd scalar pvalue2 = r(p)

test _b[1.solo] + _b[1.solo#1.base_costFP_MILopposed ] = 0
estadd scalar pvalue3 = r(p)

test _b[1.baf] + _b[1.baf#1.base_costFP_MILopposed ] = 0
estadd scalar pvalue4 = r(p)

sum `y' if treatment == 0
estadd scalar controlmean = r(mean)	
}


esttab _all ///
using "$repo/tables/appendix_table15.tex" , ///
keep(1.solo  1.solo#1.base_costFP_MILopposed  1.baf 1.baf#1.base_costFP_MILopposed   ) ///
order(1.solo  1.baf  1.solo#1.base_costFP_MILopposed 1.baf#1.base_costFP_MILopposed  ) ///
varlabels(1.solo "Own Voucher" 1.baf "BAF Voucher" 1.solo#1.base_costFP_MILopposed "Own Voucher $\times$ MIL opposed to FP" 1.baf#1.base_costFP_MILopposed "BAF Voucher $\times$ MIL opposed to FP") ///
mlabels(none) se(%9.3f) b(%9.3f)  brackets nonum  noobs nolines collabels(none)   nogaps starlevels( * 0.1 ** .05  *** .01)  ///
stats(N  controlmean pvalue1 pvalue2 pvalue3 pvalue4 , label("\midrule Observations" "Endline control mean" "\shortstack[l]{p-values:\\Own = BAF}"   "Own $\times$ MIL opposed = BAF $\times$ MIL opposed" "Own + Own $\times$ MIL opposed = 0"  "BAF + BAF $\times$ MIL opposed = 0"  ) fmt(%9.0f %9.3f %9.3f  %9.3f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccccc} \toprule") ///
posthead(" & \multicolumn{1}{c}{\textbf{Knowledge}} &  \multicolumn{1}{c}{\textbf{Attitude}} &  \multicolumn{2}{c}{\textbf{Use of FP}} &  \multicolumn{2}{c}{\textbf{Fertility}} \\ \cmidrule(lr){2-2} \cmidrule(lr){3-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7}   &  \shortstack{Number of modern\\FP method heard} & \shortstack{Afraid of\\being seen}  & \shortstack{Using a modern\\method at endline}  & \shortstack{Has used a modern\\method since baseline} &  \shortstack{Pregnancy since\\baseline} & \shortstack{Wants another\\child}   \\  & (1) & (2) & (3) & (4) & (5) & (6)\\ \midrule") ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  replace



*********************************************************************************************************************
**## Table A.16: Heterogeneous effects by mother-in-law opposition baseline on social connections and peer engagement
*********************************************************************************************************************
eststo clear
est drop _all

global outcomes outsider_new  ///
				atleast1_visithf_VoutHH2 peer_advise_FP_VoHH2

foreach y of global outcomes{
eststo reg`y': reg `y' 	i.solo##i.base_costFP_MILopposed  ///
						i.baf##i.base_costFP_MILopposed   ///
						c.base_school_yrs#i.base_costFP_MILopposed    ///
						c.base_num_friend#i.base_costFP_MILopposed    ///
						i.base_current_fp##i.base_costFP_MILopposed  ///
						i.base_wants_child##i.base_costFP_MILopposed  ///
						i.base_obc##i.base_costFP_MILopposed  ///
						c.base_mobi#i.base_costFP_MILopposed  ///
						i.base_work##i.base_costFP_MILopposed  ///
						i.base_ever_visit_fp##i.base_costFP_MILopposed   ///
						i.base_phone#i.base_costFP_MILopposed  ///
						i.base_mod_method#i.base_costFP_MILopposed ///
						i.base_village_num#i.base_costFP_MILopposed ,  r
						
test _b[1.solo] = _b[1.baf]
estadd scalar pvalue1 = r(p)

test _b[1.solo#1.base_costFP_MILopposed ] = _b[1.baf#1.base_costFP_MILopposed ]
estadd scalar pvalue2 = r(p)

test _b[1.solo] + _b[1.solo#1.base_costFP_MILopposed ] = 0
estadd scalar pvalue3 = r(p)

test _b[1.baf] + _b[1.baf#1.base_costFP_MILopposed ] = 0
estadd scalar pvalue4 = r(p)

sum `y' if treatment == 0
estadd scalar controlmean = r(mean)	
}


esttab _all ///
using "$repo/tables/appendix_table16.tex" , ///
keep(1.solo  1.solo#1.base_costFP_MILopposed  1.baf 1.baf#1.base_costFP_MILopposed   ) ///
order(1.solo  1.baf  1.solo#1.base_costFP_MILopposed 1.baf#1.base_costFP_MILopposed  ) ///
varlabels(1.solo "Own Voucher" 1.baf "BAF Voucher" 1.solo#1.base_costFP_MILopposed "Own Voucher $\times$ MIL opposed to FP" 1.baf#1.base_costFP_MILopposed "BAF Voucher $\times$ MIL opposed to FP") ///
mlabels(none) se(%9.3f) b(%9.3f)  brackets nonum  noobs nolines collabels(none)   nogaps starlevels( * 0.1 ** .05  *** .01)  ///
stats(N  controlmean pvalue1 pvalue2 pvalue3 pvalue4 , label("\midrule Observations" "Endline control mean" "\shortstack[l]{p-values:\\Own = BAF}"   "Own $\times$ MIL opposed = BAF $\times$ MIL opposed" "Own + Own $\times$ MIL opposed = 0"  "BAF + BAF $\times$ MIL opposed = 0"  ) fmt(%9.0f %9.3f %9.3f  %9.3f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lccc}\toprule") ///
 posthead(" & & \multicolumn{2}{c}{\textbf{Peer engagement}} \\ \cmidrule(lr){3-4}  & &  \multicolumn{2}{c}{Has close peers outside HH in village that: } \\ \cmidrule(lr){3-4} &  \shortstack{Number of close peers\\outside HH in village} &   \shortstack{Accompanied to\\health facility}  &  \shortstack{Advised woman\\to use FP}  \\  & (1) & (2) & (3)  \\  \midrule") ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  replace


**********************************************************************************************
**## Table A.17: Heterogeneous effects by whether women found FP use embarrassing at baseline
**********************************************************************************************
eststo clear
est drop _all

global outcomes heard_mod_method /// // Knowledge
				afraid_being_seen  /// // Attitude
				mod_method_el mod_method_since_bl /// Use of FP
				preg_ever wants_child // Fertility

foreach y of global outcomes{
eststo reg`y': reg `y' 	i.solo##i.base_costFP_embarrasing  ///
						i.baf##i.base_costFP_embarrasing   ///
						c.base_school_yrs#i.base_costFP_embarrasing    ///
						c.base_num_friend#i.base_costFP_embarrasing    ///
						i.base_current_fp##i.base_costFP_embarrasing  ///
						i.base_wants_child##i.base_costFP_embarrasing  ///
						i.base_obc##i.base_costFP_embarrasing  ///
						c.base_mobi#i.base_costFP_embarrasing  ///
						i.base_work##i.base_costFP_embarrasing  ///
						i.base_ever_visit_fp##i.base_costFP_embarrasing   ///
						i.base_phone#i.base_costFP_embarrasing  ///
						i.base_mod_method#i.base_costFP_embarrasing ///
						i.base_village_num#i.base_costFP_embarrasing ,  r
						
test _b[1.solo] = _b[1.baf]
estadd scalar pvalue1 = r(p)

test _b[1.solo#1.base_costFP_embarrasing ] = _b[1.baf#1.base_costFP_embarrasing ]
estadd scalar pvalue2 = r(p)

test _b[1.solo] + _b[1.solo#1.base_costFP_embarrasing ] = 0
estadd scalar pvalue3 = r(p)

test _b[1.baf] + _b[1.baf#1.base_costFP_embarrasing ] = 0
estadd scalar pvalue4 = r(p)

sum `y' if treatment == 0
estadd scalar controlmean = r(mean)	
}


esttab _all ///
using "$repo/tables/appendix_table17.tex" , ///
keep(1.solo  1.solo#1.base_costFP_embarrasing  1.baf 1.baf#1.base_costFP_embarrasing   ) ///
order(1.solo  1.baf  1.solo#1.base_costFP_embarrasing 1.baf#1.base_costFP_embarrasing  ) ///
varlabels(1.solo "Own Voucher" 1.baf "BAF Voucher" 1.solo#1.base_costFP_embarrasing "Own Voucher $\times$ FP Embressing" 1.baf#1.base_costFP_embarrasing "BAF Voucher $\times$ FP Embressing") ///
mlabels(none) se(%9.3f) b(%9.3f)  brackets nonum  noobs nolines collabels(none)   nogaps starlevels( * 0.1 ** .05  *** .01)  ///
stats(N  controlmean pvalue1 pvalue2 pvalue3 pvalue4 , label("\midrule Observations" "Endline control mean" "\shortstack[l]{p-values:\\Own = BAF}"   "Own $\times$ FP Embressing = BAF $\times$ FP Embressing" "Own + Own $\times$ FP Embressing = 0"  "BAF + BAF $\times$ FP Embressing = 0"  ) fmt(%9.0f %9.3f %9.3f  %9.3f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccccc} \toprule") ///
posthead(" & \multicolumn{1}{c}{\textbf{Knowledge}} &  \multicolumn{1}{c}{\textbf{Attitude}} &  \multicolumn{2}{c}{\textbf{Use of FP}} &  \multicolumn{2}{c}{\textbf{Fertility}} \\ \cmidrule(lr){2-2} \cmidrule(lr){3-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7}   &  \shortstack{Number of modern\\FP method heard} & \shortstack{Afraid of\\being seen}  & \shortstack{Using a modern\\method at endline}  & \shortstack{Has used a modern\\method since baseline} &  \shortstack{Pregnancy since\\baseline} & \shortstack{Wants another\\child}   \\  & (1) & (2) & (3) & (4) & (5) & (6)\\ \midrule") ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  replace


*********************************************************************************************************************
**## Table A.18: Heterogeneous effects on outcome indices by mother-in-law opposition to family planning at baseline
*********************************************************************************************************************

eststo clear
est drop _all	

global outcomes z_table2 z_table3 z_table4 z_table5

foreach y of global outcomes{
eststo reg`y': reg `y' 	i.solo##i.base_costFP_MILopposed  ///
						i.baf##i.base_costFP_MILopposed   ///
						c.base_school_yrs#i.base_costFP_MILopposed    ///
						c.base_num_friend#i.base_costFP_MILopposed    ///
						i.base_current_fp##i.base_costFP_MILopposed  ///
						i.base_wants_child##i.base_costFP_MILopposed  ///
						i.base_obc##i.base_costFP_MILopposed  ///
						c.base_mobi#i.base_costFP_MILopposed  ///
						i.base_work##i.base_costFP_MILopposed  ///
						i.base_ever_visit_fp##i.base_costFP_MILopposed   ///
						i.base_phone#i.base_costFP_MILopposed  ///
						i.base_mod_method#i.base_costFP_MILopposed ///
						i.base_village_num#i.base_costFP_MILopposed ,  r
						
test _b[1.solo] = _b[1.baf]
estadd scalar pvalue1 = r(p)

test _b[1.solo#1.base_costFP_MILopposed ] = _b[1.baf#1.base_costFP_MILopposed ]
estadd scalar pvalue2 = r(p)

test _b[1.solo] + _b[1.solo#1.base_costFP_MILopposed ] = 0
estadd scalar pvalue3 = r(p)

test _b[1.baf] + _b[1.baf#1.base_costFP_MILopposed ] = 0
estadd scalar pvalue4 = r(p)

sum `y' if treatment == 0
estadd scalar controlmean = r(mean)	
}


esttab _all ///
using "$repo/tables/appendix_table18.tex" , ///
keep(1.solo  1.solo#1.base_costFP_MILopposed  1.baf 1.baf#1.base_costFP_MILopposed   ) ///
order(1.solo  1.baf  1.solo#1.base_costFP_MILopposed 1.baf#1.base_costFP_MILopposed  ) ///
varlabels(1.solo "Own Voucher" 1.baf "BAF Voucher" 1.solo#1.base_costFP_MILopposed "Own Voucher $\times$ MIL opposed to FP" 1.baf#1.base_costFP_MILopposed "BAF Voucher $\times$ MIL opposed to FP") ///
mlabels(none) se(%9.3f) b(%9.3f)  brackets nonum  noobs nolines collabels(none)   nogaps starlevels( * 0.1 ** .05  *** .01)  ///
stats(N  controlmean pvalue1 pvalue2 pvalue3 pvalue4 , label("\midrule Observations" "Endline control mean" "\shortstack[l]{p-values:\\Own = BAF}"   "Own $\times$ MIL opposed = BAF $\times$ MIL opposed" "Own + Own $\times$ MIL opposed = 0"  "BAF + BAF $\times$ MIL opposed = 0"  ) fmt(%9.0f %9.3f %9.3f  %9.3f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccc} \toprule") ///
posthead(" & \multicolumn{4}{c}{\textbf{Z score}} \\ \cmidrule(lr){2-5}  & \textbf{Table 2} & \textbf{Table 3}  & \textbf{Table 4} & \textbf{Table 5} \\  & (1) & (2) & (3) & (4) \\ \midrule")  ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(25)  replace



************************************
**## Table A.19: Backlash effects
************************************
eststo clear
est drop _all

eststo reg1: reg neg_exp solo baf  $covbal $cov ib1.base_village_num , robust

	test _b[solo]=_b[baf]
	estadd scalar pvalue = r(p)
	sum neg_exp  if treatment == 0 
	estadd scalar controlmean = r(mean)
	
eststo reg2: reg sexlife_sat solo baf  $covbal $cov ib1.base_village_num if  sexlife_sat<88, robust
	test _b[solo]=_b[baf]
	estadd scalar pvalue = r(p)
	sum sexlife_sat if treatment == 0  & sexlife_sat<88
	estadd scalar controlmean = r(mean)
	
eststo reg3: reg marriage_sat solo baf  $covbal $cov ib1.base_village_num if  marriage_sat<88, robust
	test _b[solo]=_b[baf]
	estadd scalar pvalue = r(p)
	sum marriage_sat if treatment == 0  & marriage_sat<88
	estadd scalar controlmean = r(mean)
	
	
esttab reg1 reg2 reg3  ///
using "$repo/tables/appendix_table19.tex" , ///
keep(solo baf)  label mlabels(none) collabels(none) nolines se(%9.3f) b(%9.3f) starlevels( * 0.1 ** .05  *** .01)  brackets nonum  noobs nogaps ///
stats(N  controlmean pvalue , label("\midrule Observations" "Endline control mean" "p-value: Own = BAF" ) fmt(%9.0f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lccc} \toprule") ///
 posthead("   &  \textbf{\shortstack{Negative experience\\with FP}} & \textbf{\shortstack{Satisfaction with\\sex life}}  & \textbf{\shortstack{Marital\\satisfaction}}  \\  & (1) & (2) & (3)  \\ \midrule") ///
 postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
 sfmt(%9.2f) varwidth(30)  replace


*****************************************************************************************************************************************
**## Table A.20: Heterogeneous effects of voucher receipt on clinic visits and family planning use by relative poverty status at baseline
*****************************************************************************************************************************************
eststo clear
est drop _all

global outcomes  visit_adc_fp_corr visit_any_fp_new_corr mod_method_since_bl

foreach y of global outcomes{
eststo reg`y'0: reg `y' i.treat##i.base_poor  ///
						c.base_school_yrs#i.base_poor ///
						c.base_num_friend#i.base_poor   ///
						i.base_current_fp##i.base_poor ///
						i.base_wants_child##i.base_poor ///
						i.base_obc##i.base_poor ///
						c.base_mobi#i.base_poor ///
						i.base_work##i.base_poor ///
						i.base_ever_visit_fp##i.base_poor  ///
						i.base_phone##i.base_poor  ///
						i.base_mod_method##i.base_poor ///
						i.base_village_num##i.base_poor ,  r
						
sum `y' if treatment == 0 
estadd scalar controlmean = r(mean)	

test _b[1.treat] + _b[1.treat#1.base_poor ] = 0
estadd scalar pvalue = r(p)

}

esttab regvisit_adc_fp_corr0 regvisit_any_fp_new_corr0 regmod_method_since_bl0  ///
using "$repo/tables/appendix_table20.tex" , ///
keep(1.treat  1.treat#1.base_poor  ) ///
order(1.treat  1.treat#1.base_poor) ///
varlabels(1.treat "Any Voucher"  1.treat#1.base_poor "Any Voucher $\times$ Poor at baseline") ///
mlabels(none) collabels(none) nolines se(%9.3f) b(%9.3f)  brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ///
stats(N  controlmean pvalue, label("\midrule Observations"  "Endline control mean" "\shortstack[l]{p-value:\\Any Voucher + Any Voucher $\times$ Poor = 0}") fmt(%9.0f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lcccc} \toprule") ///
posthead(" &   \textbf{\shortstack{Visited the ADC\\clinic}} & \textbf{\shortstack{Visited any\\clinic}} & \textbf{\shortstack{Using a modern\\method since baseline}} \\  & (1) & (2) & (3)   \\ \midrule") ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
 sfmt(%9.2f) varwidth(25)  replace
 

 
**********************************************************
**## Table A.21: Treatment-on-the-treated (TOT) estimates
**********************************************************

eststo clear
est drop _all

global mainoutcomes ask_peer_adc ///
					visit_adc_fp_corr visit_any_fp_new_corr ///
					mod_method_since_bl outsider_new ///
					heard_mod_method /// // Knowledge
					afraid_being_seen  /// // Attitude
					preg_ever wants_child  // Intension
 
foreach y of global mainoutcomes{
	
eststo reg_`y': ivreg2 `y' (treat_receive_solo treat_receive_baf=solo baf) $covbal $cov  i.base_village_num  , r

test _b[treat_receive_solo]=_b[treat_receive_baf]

	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0 
	estadd scalar controlmean = r(mean)			
}


esttab  reg_ask_peer_adc reg_visit_adc_fp_corr ///
		reg_visit_any_fp_new_corr reg_mod_method_since_bl ///
		reg_outsider_new ///
using "$repo/tables/appendix_table21.tex" , ///
keep(treat_receive_solo treat_receive_baf) ///
label mlabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ///
stats(N  pvalue controlmean, label("Observations" "p-value: Own=BAF" "Endline control mean") fmt(%9.0f %9.3f %9.3f)) ///
prehead("\begin{tabular}{lccccc} \toprule") ///
posthead("   & \textbf{\shortstack{Sought company\\to visit the ADC}} & \textbf{\shortstack{Visited the\\ADC}}  & \textbf{\shortstack{Visited any\\clinic}} & \textbf{\shortstack{Using modern\\FP method\\since baseline}}  & \textbf{\shortstack{Number of close\\peers outside\\HH in village}} \\ \textbf{Panel A}  & (1) & (2) & (3) & (4) & (5) \\ \midrule")  ///
postfoot("\midrule") ///
sfmt(%9.2f) varwidth(30) replace
 
 
esttab  reg_heard_mod_method reg_afraid_being_seen  ///
		reg_preg_ever reg_wants_child ///  
using "$repo/tables/appendix_table21.tex" , ///
keep(treat_receive_solo treat_receive_baf) ///
label mlabels(none) se(%9.3f) b(%9.3f)  ///
brackets nonum  noobs nogaps starlevels( * 0.1 ** .05  *** .01) ///
stats(N  pvalue controlmean, label("Observations" "p-value: Own=BAF" "Endline control mean") fmt(%9.0f %9.3f %9.3f)) ///
prehead("") ///
 posthead("   & \textbf{\shortstack{Number of modern\\FP method heard}} & \textbf{\shortstack{Afraid of\\being seen}} &  \textbf{\shortstack{Pregnancy since\\baseline}} & \textbf{\shortstack{Wants another\\child}} & \\ \textbf{Panel B}  & (6) & (7) & (8) & (9) & \\ \midrule")  ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") sfmt(%9.2f) varwidth(30) append


*********************************************************************************************************************
**## Table A.22: Robustness check: Treatment effects on main outcomes, using PDS Lasso approach for control selection
*********************************************************************************************************************

eststo clear
est drop _all

global mainoutcomes ask_peer_adc ///
					visit_adc_fp_corr visit_any_fp_new_corr ///
					mod_method_since_bl outsider_new ///
					heard_mod_method /// // Knowledge
					afraid_being_seen  /// // Attitude
					wants_child preg_ever // Intension

global covbal base_school_yrs base_current_fp base_wants_child base_num_friend
global cov  base_mobi base_work base_ever_visit_fp base_mod_method base_phone


foreach y of global mainoutcomes{

* PSD Lasso
	eststo r`y': qui pdslasso `y' solo baf $covbal ($cov i.base_village_num), r
	test _b[solo]=_b[baf]
	estadd scalar pvalue = r(p)
	sum `y' if treatment == 0 
	estadd scalar controlmean = r(mean)	

}



esttab  rask_peer_adc rvisit_adc_fp_corr rvisit_any_fp_new_corr  ///  
		rmod_method_since_bl routsider_new ///
using "$repo/tables/appendix_table22.tex" , ///
booktabs fragment nogaps mlabels(none) nonum  nolines collabels(none) label se(%9.3f) b(%9.3f) brackets keep(solo baf) starlevels( * 0.1 ** .05  *** .01) ///
stats(N controlmean pvalue , label("\midrule Observations" "Endline control mean" "p-value: Own = BAF" ) fmt(%9.0f %9.3f  %9.3f)) ///
prehead("\begin{tabular}{lccccc}\toprule") ///
 posthead("   & \textbf{\shortstack{Sought company\\to visit the ADC}} & \textbf{\shortstack{Visited the\\ADC}}  & \textbf{\shortstack{Visited any\\clinic}} & \textbf{\shortstack{Using modern\\FP method\\since baseline}}  & \textbf{\shortstack{Number of close\\peers outside\\HH in village}} \\ \textbf{Panel A}  & (1) & (2) & (3) & (4) & (5) \\ \midrule") ///
postfoot("\midrule") ///
sfmt(%9.2f) varwidth(30) substitute(\_ _)  replace

esttab rheard_mod_method rafraid_being_seen rwants_child rpreg_ever  ///  
using "$repo/tables/appendix_table22.tex" , ///
booktabs fragment nogaps mlabels(none) nonum  nolines collabels(none) label se(%9.3f) b(%9.3f) brackets keep(solo baf) starlevels( * 0.1 ** .05  *** .01) ///
stats(N controlmean pvalue , label("\midrule Observations" "Endline control mean" "p-value: Own = BAF" ) fmt(%9.0f %9.3f  %9.3f)) ///
prehead("") ///
posthead("   & \textbf{\shortstack{Number of modern\\FP method heard}} & \textbf{\shortstack{Afraid of\\being seen}}  & \textbf{\shortstack{Wants another\\child}} &  \textbf{\shortstack{Pregnancy since\\baseline}} & \\ \textbf{Panel B}  & (6) & (7) & (8) & (9) & \\ \midrule")  ///
postfoot("\bottomrule \\[-5ex] \end{tabular}") ///
sfmt(%9.2f) varwidth(30)  substitute(\_ _)  append


*******************************************************************************************************
**## Table A.23: Balance check on attrition rates and phone survey completion rates by treatment group
*******************************************************************************************************

preserve
* Loading data

clear all

* Endline Data including attrition
use "$repo/data_endline_all.dta", clear

gen phone2 = phone
replace phone2 = 0 if phone == . & attrition != 1

la var phone2 "Phone interview in wave 2"
la var attrition_w2 "Attrition in wave 2"


eststo clear
est drop _all
 
global vars attrition_w2 phone2 

* Mean . SD of each treatment arm:
eststo control:  estpost summarize $vars if treatment == 0
eststo own:  	 estpost summarize $vars if treatment == 1 
eststo baf:  	 estpost summarize $vars if treatment == 2 

* Pair-differences
eststo diffcontrolown:  estpost ttest $vars if treatment!=2, by(solo) unequal 
* Adding scalars of F-Test of join significance. 
reg solo $vars   if treatment!=2
estadd scalar F_Obs = `e(N)': diffcontrolown
testparm $vars
estadd scalar F_pvalue = r(p): diffcontrolown

eststo diffcontrolbaf:   estpost ttest $vars if treatment!=1, by(baf) unequal 
* Adding scalars of F-Test of join significance. 
reg baf $vars   if treatment!=1
estadd scalar F_Obs = `e(N)': diffcontrolbaf
testparm $vars
estadd scalar F_pvalue = r(p): diffcontrolbaf

eststo diffownbaf:   estpost ttest $vars if treatment!=0, by(baf) unequal 
* Adding scalars of F-Test of join significance. 
reg baf $vars  if treatment!=0
estadd scalar F_Obs = `e(N)': diffownbaf
testparm $vars
estadd scalar F_pvalue = r(p): diffownbaf


* Export Balance Table: 

esttab ///
control own baf  diffcontrolown diffcontrolbaf diffownbaf ///
using "$repo/tables/appendix_table23.tex"  , ///
cells("count(pattern(1 1 1 0 0 0 ) fmt(0)) mean(pattern(1 1 1 0 0 0) fmt(3)) b(star pattern(0 0 0 1 1 1) fmt(3))" ". sd(pattern(1 1 1 0 0 0) par fmt(3))" ) ///
label collabels(none) nonum plain nomtitle noobs not tex starlevels(* 0.1 ** .05  *** .01) ///
prehead("\begin{tabular}{lccccccccc} \toprule & \multicolumn{2}{c}{Control (C)}   & \multicolumn{2}{c}{Own}  &  \multicolumn{2}{c}{BAF}  & C - Own & C - BAF & Own - BAF \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(lr){8-8} \cmidrule(lr){9-9} \cmidrule(lr){10-10}  & N & Mean/SD & N & Mean/SD & N & Mean/SD & Diff. & Diff. & Diff. \\ & (1) & (2) &(3)& (4) & (5) & (6) & (7) & (8) & (9) \\ \midrule") ///
posthead("") ///
postfoot("\bottomrule  \\[-5ex] \end{tabular}") replace

restore


******************************************************************
**## Table A.24: Balance at baseline, by endline attrition status
******************************************************************
preserve

* Baseline Data 
* Need baseline data for this table only (to have attrition_w2 == 1)

use "$repo/data_baseline.dta", clear

drop if missing(base_school_yrs, base_current_fp, ///
				base_wants_child, base_num_friend, ///
				base_mobi, base_work, base_ever_visit_fp, ///
				base_mod_method)

***GENERATE TREATMENT ARM DUMMIES

capture{
tab treatment, gen(treatment_)
}
la var treatment_1 "Control Arm"
la var treatment_2 "Own Voucher"
la var treatment_3 "BAF Voucher"


global balance base_age base_school_yrs base_w_hindu base_scst base_obc 	///
			   base_ghunghat base_work base_livewMIL base_mobi 				///
			   base_asset_score base_num_friend base_outsider 			    ///
			   base_no_children base_wants_child base_current_fp 			///
			   base_mod_method base_ever_visit_fp base_costFP_MILopposed

eststo clear
est drop _all

* Mean . SD of each group:
eststo nonatt:  estpost  summarize  $balance treatment_2 treatment_3  if attrition_w2 == 0
eststo att:  	estpost  summarize  $balance treatment_2 treatment_3  if attrition_w2 == 1 
* Pair-differences
eststo diff:  estpost ttest  $balance treatment_2 treatment_3 , by(attrition_w2) unequal 
* Adding scalars of F-Test of join significance. : using regression
qui reg attrition_w2  $balance treatment_2 treatment_3

test	base_age == base_school_yrs == base_w_hindu == base_scst == base_obc == ///
		base_ghunghat == base_work == base_livewMIL == base_mobi ==	 		 ///
		base_asset_score == base_num_friend == base_outsider ==  		     ///
		base_no_children == base_wants_child == base_current_fp ==   		 ///
		base_mod_method == base_ever_visit_fp == base_costFP_MILopposed == ///
		treatment_2 == treatment_3
			
estadd scalar F_Obs = `e(N)': diff
estadd scalar F_pvalue = r(p):diff

* Export Balance Table: 
esttab ///
nonatt att diff ///
using "$repo/tables/appendix_table24.tex"  , ///
cells("count(pattern(1 1 0 ) fmt(0)) mean(pattern(1 1 0) fmt(3)) b(star pattern(0 0 1 ) fmt(3))" ". sd(pattern(1 1 0 ) par fmt(3))" ) ///
label  collabels(none) nonum plain nomtitle noobs not tex starlevels(* 0.1 ** .05  *** .01) ///
stats(F_pvalue F_Obs, label("\midrule F-test of joint significance: p-value" "F-test: number of observations" ) fmt( %9.3f  %9.0f )) ///
prehead("\begin{tabular}{lcccccc} \toprule & \multicolumn{2}{c}{Non-attritor} & \multicolumn{2}{c}{Attritor} & \multicolumn{2}{c}{Non-attritor -- Attritor}  \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7}	& N & Mean/SD & N & Mean/SD & Diff. & Norm. Diff. \\	& (1)   & (2)  & (3)  & (4)  & (5) & (6) \\ \midrule ") ///
posthead("") ///
postfoot("\bottomrule  \\[-5ex] \end{tabular}") replace


* Export Balance Table:  Part 2 - Normalized Differences

// Need to fix this (Added this column in latex table using R)

* Normalized Differences
qui stddiff $balance treatment_2 treatment_3 , by(attrition_w2) coh
matrix ndif = r(stddiff)
mat2txt, matrix(ndif) saving("$repo/tables/appendix_table24_ndiff.csv") replace


restore

* Please refer to the R script file to construct final formatted appendix_table24.tex file.

************************************************************
**## Table A.25: Balance at baseline, by endline survey mode
************************************************************


capture{
tab treatment, gen(treatment_)
}
la var treatment_1 "Control Arm"
la var treatment_2 "Own Voucher"
la var treatment_3 "BAF Voucher"

* Mean . SD of each group:
eststo person:  estpost  summarize $balance treatment_2 treatment_3 if base_phone==0
eststo phone:  	estpost  summarize $balance treatment_2 treatment_3 if base_phone==1 
* Pair-differences
eststo diff:  estpost ttest $balance treatment_2 treatment_3, by(base_phone) unequal 
* Adding scalars of F-Test of join significance. 
qui reg base_phone  $balance treatment_2 treatment_3

test	base_age == base_school_yrs == base_w_hindu == base_scst == base_obc == ///
		base_ghunghat == base_work == base_livewMIL == base_mobi ==	 		 ///
		base_asset_score == base_num_friend == base_outsider ==  		     ///
		base_no_children == base_wants_child == base_current_fp ==   		 ///
		base_mod_method == base_ever_visit_fp == base_costFP_MILopposed == ///
		treatment_2 == treatment_3
			
estadd scalar F_Obs = `e(N)':diff
estadd scalar F_pvalue = r(p):diff

* Export Balance Table: 
esttab ///
person phone diff ///
using "$repo/tables/appendix_table25.tex"  , ///
cells("count(pattern(1 1 0 ) fmt(0)) mean(pattern(1 1 0) fmt(3)) b(star pattern(0 0 1 ) fmt(3))" ". sd(pattern(1 1 0 ) par fmt(3))" ) ///
label  collabels(none) nonum plain nomtitle noobs not tex starlevels(* 0.1 ** .05  *** .01) ///
stats(F_pvalue F_Obs, label("\midrule F-test of joint significance: p-value" "F-test: number of observations" ) fmt( %9.3f  %9.0f )) ///
prehead("\begin{tabular}{lcccccc} \toprule & \multicolumn{2}{c}{In-person} & \multicolumn{2}{c}{Phone} &  \multicolumn{2}{c}{In-person -- Phone}       \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7}	& N & Mean/SD & N   & Mean/SD          & Diff. & Norm. Diff. \\	& (1)   & (2)  & (3)  & (4)  & (5) & (6)        \\\midrule") ///
posthead("") ///
postfoot("\bottomrule  \\[-5ex] \end{tabular}") replace


* Export Balance Table:  Part 2 - Normalized Differences

// Added this column in latex table using R script. Run R script to add this column.

* Normalized Differences
qui stddiff $balance treatment_2 treatment_3, by(base_phone) coh
matrix ndif = r(stddiff)
mat2txt, matrix(ndif) saving("$repo/tables/appendix_table25_ndiff.csv") replace

* Please refer to the R script file to construct final formatted appendix_table25.tex file.

**********************************************************************************************************************
**## Table A.26: Lee Bounds test, accounting for attrition sample only  
**## Table A.27: Lee bounds test, accounting for attrition sample and phone survey sample with missing outcome values 
**********************************************************************************************************************


* Loading data

clear all

* Endline Data including attrition
use "$repo/data_endline_all.dta", clear

gen phone2 = phone
replace phone2 = 0 if phone == . & attrition != 1

la var phone2 "Phone interview in wave 2"
la var attrition_w2 "Attrition in wave 2"

**### Only for attrited


// Define attrited = 0; needed for leebounds
cap drop atr
gen atr = 1 if attrition_w2 == 0
replace atr = 0 if attrition_w2 == 1


				
preserve

clear
set obs 1

gen y 		= "Outcome"
gen treat 	= "Treatment"

gen lb_b 	= .
gen lb_se 	= .
gen lb_p 	= .

gen ub_b 	= .
gen ub_se 	= .
gen ub_p 	= .
 
gen obs = .

save "$repo/tables/appendix_table26.dta", replace

restore


global vars 	ask_peer_adc asked_hmil asked_other asked_sil asked_nonfam ///
				visit_adc_fp_corr visit_any_fp_new_corr visit_adc_alone ///
				visit_adc_w_hhmil_new visit_adc_w_nohmil_new visit_adc_w_sil_new ///
				visit_adc_w_other_new ///
				mod_method_el mod_method_since_bl preg_ever ///
				outsider_new  ///
				atleast1_visithf_VoutHH peer_advise_FP_VoHH  ///
				afraid_being_seen


				
foreach y of global vars {


	// Without control: unadjusted
	
	// OWN
	leebounds `y' treatment if treatment != 2, ///
				select(atr) cieffect
				
		preserve			
		matrix lee_res = r(table) 

		clear
		set obs 1

		gen y 		= "`y'"
		gen treat 	= "OWN"

		gen lb_b 	= lee_res[1,1]
		gen lb_se 	= lee_res[2,1]
		gen lb_p 	= lee_res[4,1]

		gen ub_b 	= lee_res[1,2]
		gen ub_se 	= lee_res[2,2]
		gen ub_p 	= lee_res[4,2]
		
		gen obs = e(N)

		format lb_p %9.6f
		format ub_p %9.6f
		

		append using "$repo/tables/appendix_table26.dta"
		save "$repo/tables/appendix_table26.dta", replace

		restore


	// BAF
	leebounds `y' treatment if treatment != 1, ///
				select(atr) cieffect

		preserve
		matrix lee_res = r(table) 


		clear
		set obs 1

		gen y 		= "`y'"
		gen treat 	= "BAF"

		gen lb_b 	= lee_res[1,1]
		gen lb_se 	= lee_res[2,1]
		gen lb_p 	= lee_res[4,1]

		gen ub_b 	= lee_res[1,2]
		gen ub_se 	= lee_res[2,2]
		gen ub_p 	= lee_res[4,2]
		
		gen obs = e(N)

		format lb_p %9.6f
		format ub_p %9.6f

		append using "$repo/tables/appendix_table26.dta"
		save "$repo/tables/appendix_table26.dta", replace

		restore
			
}

preserve
use "$repo/tables/appendix_table26.dta", clear
drop if y == "Outcome"
sort y treat

cap drop baf_b baf_se
bysort y: gen baf_b = lb_b[_n-1]
bysort y: gen baf_se = lb_se[_n-1]
bysort y: gen baf_obs = obs[_n-1]
gen diff_stat_lb = (lb_b - baf_b)/sqrt(lb_se^2 + baf_se^2)
gen diff_pval_lb = 2 * ttail(obs + baf_obs - 2, abs(diff_stat_lb))

cap drop baf_b baf_se
bysort y: gen baf_b = ub_b[_n-1]
bysort y: gen baf_se = ub_se[_n-1]
gen diff_stat_ub = (ub_b - baf_b)/sqrt(ub_se^2 + baf_se^2)
gen diff_pval_ub = 2 * ttail(obs + baf_obs - 2, abs(diff_stat_ub))

cap drop baf_b baf_se baf_obs diff_stat_lb  diff_stat_ub

format diff_pval_lb %9.6f
format diff_pval_ub %9.6f


save "$repo/tables/appendix_table26.dta", replace

restore			


**### Only for attrited and missing


preserve

clear
set obs 1

gen y 		= "Outcome"
gen treat 	= "Treatment"

gen lb_b 	= .
gen lb_se 	= .
gen lb_p 	= .

gen ub_b 	= .
gen ub_se 	= .
gen ub_p 	= .

gen obs = .

save "$repo/tables/appendix_table27.dta", replace

restore


global vars 	ask_peer_adc asked_hmil asked_other asked_sil asked_nonfam ///
				visit_adc_fp_corr visit_any_fp_new_corr visit_adc_alone ///
				visit_adc_w_hhmil_new visit_adc_w_nohmil_new visit_adc_w_sil_new ///
				visit_adc_w_other_new ///
				mod_method_el mod_method_since_bl preg_ever ///
				outsider_new  ///
				atleast1_visithf_VoutHH peer_advise_FP_VoHH  ///
				afraid_being_seen


foreach y of global vars {
	
	// Define atr = 0; needed for leebounds
	capture drop atr
	gen atr = 0
	replace atr = 1 if attrition_w2 == 0 & `y' !=  .

	// Without control: unadjusted
	
	// OWN
	leebounds `y' treatment if treatment != 2, ///
				select(atr) cieffect
				
		preserve			
		matrix lee_res = r(table) 

		clear
		set obs 1

		gen y 		= "`y'"
		gen treat 	= "OWN"

		gen lb_b 	= lee_res[1,1]
		gen lb_se 	= lee_res[2,1]
		gen lb_p 	= lee_res[4,1]

		gen ub_b 	= lee_res[1,2]
		gen ub_se 	= lee_res[2,2]
		gen ub_p 	= lee_res[4,2]
		
		gen obs = e(N)

		format lb_p %9.6f
		format ub_p %9.6f

		append using "$repo/tables/appendix_table27.dta"
		save "$repo/tables/appendix_table27.dta", replace

		restore


	// BAF
	leebounds `y' treatment if treatment != 1, ///
				select(atr) cieffect

		preserve
		matrix lee_res = r(table)  


		clear
		set obs 1

		gen y 		= "`y'"
		gen treat 	= "BAF"

		gen lb_b 	= lee_res[1,1]
		gen lb_se 	= lee_res[2,1]
		gen lb_p 	= lee_res[4,1]

		gen ub_b 	= lee_res[1,2]
		gen ub_se 	= lee_res[2,2]
		gen ub_p 	= lee_res[4,2]
		
		gen obs = e(N)

		format lb_p %9.6f
		format ub_p %9.6f

		append using "$repo/tables/appendix_table27.dta"
		save "$repo/tables/appendix_table27.dta", replace

		restore
		
	drop atr		
}

preserve
use "$repo/tables/appendix_table27.dta", clear
drop if y == "Outcome"
sort y treat

cap drop baf_b baf_se
bysort y: gen baf_b = lb_b[_n-1]
bysort y: gen baf_se = lb_se[_n-1]
bysort y: gen baf_obs = obs[_n-1]
gen diff_stat_lb = (lb_b - baf_b)/sqrt(lb_se^2 + baf_se^2)
gen diff_pval_lb = 2 * ttail(obs + baf_obs - 2, abs(diff_stat_lb))

cap drop baf_b baf_se
bysort y: gen baf_b = ub_b[_n-1]
bysort y: gen baf_se = ub_se[_n-1]
gen diff_stat_ub = (ub_b - baf_b)/sqrt(ub_se^2 + baf_se^2)
gen diff_pval_ub = 2 * ttail(obs + baf_obs - 2, abs(diff_stat_ub))

cap drop baf_b baf_se baf_obs diff_stat_lb  diff_stat_ub

format diff_pval_lb %9.6f
format diff_pval_ub %9.6f

save "$repo/tables/appendix_table27.dta", replace

restore	

* Please refer to the R script file to construct final formatted appendix_table26.tex and appendix_table27.tex files.


***************************************************************************************************************************************************
**## Table A.28: Inverse Probability Weighted (IPW) estimation, accounting for attrition sample only 
**## Table A.29: Inverse Probability Weighted (IPW) estimation, accounting for attrition sample and phone survey sample with missing outcome values 

****************************************************************************************************************************************************

global covbal base_school_yrs base_current_fp base_wants_child base_num_friend
global cov  base_mobi base_work base_ever_visit_fp base_mod_method base_phone


global vars 	ask_peer_adc asked_hmil asked_other asked_sil asked_nonfam ///
				visit_adc_fp_corr visit_any_fp_new_corr visit_adc_alone ///
				visit_adc_w_hhmil_new visit_adc_w_nohmil_new visit_adc_w_sil_new ///
				visit_adc_w_other_new ///
				mod_method_el mod_method_since_bl preg_ever ///
				outsider_new  ///
				atleast1_visithf_VoutHH peer_advise_FP_VoHH  ///
				afraid_being_seen
				

**### Only for attrited

logit attrition_w2 solo baf $covbal $cov // Baseline covariates
cap drop p_attrit ipw
predict p_attrit, pr
gen ipw = 1 / (1 - p_attrit)


preserve
clear
set obs 1

gen y 		= "Outcome"

gen own_b 	= .
gen own_se 	= .
gen own_p 	= .

gen baf_b 	= .
gen baf_se 	= .
gen baf_p 	= .

gen joint_p = .

gen obs = .

save "$repo/tables/appendix_table28.dta", replace
restore


foreach y of global vars {
	qui reg `y' solo baf $covbal $cov i.base_village_num ///
			[pweight=ipw], r
		

		matrix ipw = r(table)
		
		
		
		preserve
		clear
		set obs 1

		gen y 		= "`y'"

		gen own_b 	= ipw[1,1]
		gen own_se 	= ipw[2,1]
		gen own_p 	= ipw[4,1]

		gen baf_b 	= ipw[1,2]
		gen baf_se 	= ipw[2,2]
		gen baf_p 	= ipw[4,2]
		
		gen obs = e(N)
		
		test _b[solo] = _b[baf]
		gen joint_p = r(p)
		
		append using "$repo/tables/appendix_table28.dta"
		save "$repo/tables/appendix_table28.dta", replace
		restore
}

preserve
use "$repo/tables/appendix_table28.dta", clear
drop if y == "Outcome"
save "$repo/tables/appendix_table28.dta", replace

restore	



**### Only for attrited and missing



preserve
clear
set obs 1

gen y 		= "Outcome"

gen own_b 	= .
gen own_se 	= .
gen own_p 	= .

gen baf_b 	= .
gen baf_se 	= .
gen baf_p 	= .

gen joint_p = .

gen obs = .

save "$repo/tables/appendix_table29.dta", replace
restore


foreach y of global vars {
	
	cap drop attrt
	gen attrt = attrition_w2
	replace attrt = 1 if `y' == .
	
	logit attrt solo baf $covbal $cov // Baseline covariates
	cap drop p_attrit
	predict p_attrit, pr
	cap drop ipw
	gen ipw = 1 / (1 - p_attrit)
	cap drop attrt

	qui reg `y' solo baf $covbal $cov i.base_village_num ///
			[pweight=ipw], r
				 

		matrix ipw = r(table)
		
		preserve
		clear
		set obs 1

		gen y 		= "`y'"

		gen own_b 	= ipw[1,1]
		gen own_se 	= ipw[2,1]
		gen own_p 	= ipw[4,1]

		gen baf_b 	= ipw[1,2]
		gen baf_se 	= ipw[2,2]
		gen baf_p 	= ipw[4,2]
		
		gen obs = e(N)
		
		test _b[solo] = _b[baf]
		gen joint_p = r(p)
		
		append using "$repo/tables/appendix_table29.dta"
		save "$repo/tables/appendix_table29.dta", replace
		restore
}

preserve
use "$repo/tables/appendix_table29.dta", clear
drop if y == "Outcome"
save "$repo/tables/appendix_table29.dta", replace

restore	

* Please refer to the R script file to construct final formatted appendix_table28.tex and appendix_table29.tex files.

********************************************************************
**## Table A.30: Summary of intervention cost components (10 months)

* Created separately, please refer to section C of the Online Appendix 
*********************************************************************

*********************************************************************
**## Table A.31: Cost-effectiveness of the BAF intervention

* Created separately, please refer to section C of the Online Appendix 
*********************************************************************


// Clear everything

clear all
macro drop _all
